How do I set the Initial Directory on an OpenFileDIalog to the users `Downloads` folder in C#
Posted
by
JMK
on Stack Overflow
See other posts from Stack Overflow
or by JMK
Published on 2012-03-18T17:52:43Z
Indexed on
2012/03/18
17:57 UTC
Read the original article
Hit count: 594
c#
|openfiledialog
Ok so I have an OpenFileDialog and I want to set the initial directory to the users 'Download' folder. This is an internal application and, therefore, I am sure that the user will be using Windows 7.
var ofd = new OpenFileDialog();
//This doesn't work
ofd.InitialDirectory =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Downloads");
//This doesn't work either
ofd.InitialDirectory = @"%USERPROFILE%\Downloads";
ofd.Filter = "Zip Files|*.zip";
ofd.ShowDialog();
txtFooBar.Text = ofd.FileName;
I have tried the above so far and neither work. No Exception is thrown, it just doesn't set the initial directory to the downloads folder.
Where am I going wrong?
Thanks
© Stack Overflow or respective owner